//
//  NoteDetailsView.m
//  geoNotes
//
//  Created by Administrator on 6/23/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "NoteDetailsView.h"
#import "NoteAnnotation.h"
@implementation NoteDetailsView
@synthesize navBar;
@synthesize mapView;
@synthesize titleLabel;
@synthesize messageField,note,delegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization#
       

    }
    return self;
}
- (void)dealloc
{
    [titleLabel release];
    [messageField release];
    [navBar release];
    [mapView release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    if(note){
        [note retain];
        NSLog(@"show details for note %@",[note description]);
        [titleLabel setText:note.title];
        [messageField setText:note.message];
    }
}

- (void)viewDidUnload
{
    [self setTitleLabel:nil];
    [self setMessageField:nil];
    [self setNavBar:nil];
    [self setMapView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
-(void) viewWillAppear:(BOOL)animated{
  
        CLLocationCoordinate2D mapCenter;
        mapCenter.latitude = [note.lat doubleValue];
        mapCenter.longitude = [note.lon doubleValue];
        
        MKCoordinateSpan mapSpan;
        mapSpan.latitudeDelta = 0.005;
        mapSpan.longitudeDelta = 0.005;
        
        MKCoordinateRegion mapRegion;
        mapRegion.center = mapCenter;
        mapRegion.span = mapSpan;
        [mapView addAnnotation:[[[NoteAnnotation alloc] initWithCoordinate:mapCenter andTitle:note.title andSubtitle:note.message]autorelease]];
        self.mapView.region = mapRegion;
        self.mapView.mapType = MKMapTypeStandard;
    
        
    
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)done:(id)sender {
    [self.delegate noteDetailsViewDidFinish];
}

- (IBAction)onDelete:(id)sender {
    [self.delegate noteDetailsViewDidFinish:self withDelete:note];
    
}


@end
